#include "light.h"
#include "count.h"

light::light() {
	length_width_ratio = 0;
	relative_area_ratio = 0;

	approxPolyDP_data = 0;
	approxPolyDP_count = 0;

	rect_length = 0;
	rect_width = 0;
	slope_of_width = 0;
}

light::light(vector<Point> input_contour) {
	contour = input_contour;
	rect = minAreaRect(contour);
	rect_length = max(rect.size.height, rect.size.width);
	rect_width = min(rect.size.height, rect.size.width);
	count_date();
}

void light::count_date() {
	count_length_width_ratio();
	count_relative_area_ratio();
	count_approxPolyDP_count();
	count_slope_of_width();
};

void light::count_length_width_ratio() {
	length_width_ratio = rect_length / rect_width;
};

void light::count_relative_area_ratio() {
	double area=contourArea(contour);
	double rect_area = rect.size.area();
	relative_area_ratio = area / rect_area;
};

void light::count_approxPolyDP_count() {
	approxPolyDP(contour, approxPolyDP_data, 12, 1);
	approxPolyDP_count = approxPolyDP_data.rows;
};

void light::count_slope_of_width() {
	Point2f temp[4],point[2];
	rect.points(temp);
	if (count_dis(temp[0], temp[1]) < count_dis(temp[1], temp[2]))
	{
		point[0] = temp[0];
		point[1] = temp[1];
	}
	else
	{
		point[0] = temp[2];
		point[1] = temp[1];
	}

	slope_of_width = (point[0].y - point[1].y) / (point[0].x - point[1].x);
}